<script setup lang="ts">
import {useAccount} from "./utils/hook";
import {computed, nextTick, onMounted, ref} from "vue";
import {PureTableBar} from "@/components/RePureTableBar";
import {useRenderIcon} from "@/components/ReIcon/src/hooks";
import {deviceDetection, useResizeObserver} from "@pureadmin/utils";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
import { useRoute } from 'vue-router'
const route = useRoute()
import Refresh from "@iconify-icons/ep/refresh";
import Close from "@iconify-icons/ep/close";
import Check from "@iconify-icons/ep/check";

defineOptions({
  name: "BusinessReturnLog"
});


const formRef = ref();
const tableRef = ref();
const contentRef = ref();
const batchItem = ref('1')
const size = ref("small");
const {
  form, isShow, curRow, loading, columns, exportExcel,salesman_arr,columns1,
  rowStyle, statusList, selectedNum, onSelectionCancel, onbatchAct,sortChange,
  dataList, treeData,treeProps, isLinkage, pagination, isExpandAll, isSelectAll, treeSearchValue,
  onSearch, shopList,searchCondList,
  resetForm, openDialog, handleMenu,  handleSave, handleDelete, filterMethod, transformI18n, onQueryChanged, handleSizeChange, handleCurrentChange,handleSelectionChange
} = useAccount(tableRef);

onMounted(() => {
  useResizeObserver(contentRef, async () => {
    await nextTick();
  });
});
</script>

<template>
  <div class="main">
    <el-tabs v-model="form.tab_id" class="bg-bg_color px-3" @tab-click="onSearch" >
      <el-tab-pane label="奖项设置" name="1" style="margin-left: 20px;margin-left: 20px;">
        <div ref="contentRef" :class="['flex', deviceDetection() ? 'flex-wrap' : '']">
          <PureTableBar
            :class="[isShow && !deviceDetection() ? '!w-[60vw]' : 'w-full']"
            style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
            :title="t(route.meta.title)"
            :columns="columns"
            @refresh="onSearch"
          >
            <template #title>
              <div></div>
            </template>
            <template v-slot="{ size, dynamicColumns }">
              <pure-table ref="tableRef" align-whole="center" showOverflowTooltip
                          table-layout="auto" :loading="loading" :size="size" adaptive @sort-change="sortChange"
                          :row-style="rowStyle" :adaptiveConfig="{ offsetBottom: 108 }"
                          :data="dataList" :columns="dynamicColumns" :border="true" :pagination="{ ...pagination, size }"  @page-size-change="handleSizeChange"
                          @page-current-change="handleCurrentChange"
                          :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }">
                <template #operation="{ row }">
                  <el-popconfirm :title="t('buttons.deleteConfirm')" @confirm="handleDelete(row)">
                    <template #reference>
                      <el-button v-perms="'order_apply:btn:delete'"  class="reset-margin" link type="primary" :size="size">
                        {{ t("buttons.delete") }}
                      </el-button>
                    </template>
                  </el-popconfirm>
                </template>
              </pure-table>
            </template>
          </PureTableBar>
        </div>
      </el-tab-pane>
      <el-tab-pane label="中奖记录" name="2">
        <el-form ref="formRef" :inline="true" :model="form" :size="size" class="search-form bg-bg_color w-[99/100] pl-8  overflow-auto">
          <el-form-item label="业务员" prop="creator_id">
            <el-select v-model="form.creator_id" placeholder="业务员" clearable filterable class="!w-[100px]">
              <el-option v-for="item in salesman_arr" :label="item.dept?.name+'-'+item.username" :value="item.id" :disabled="item.id==''"/>
            </el-select>
          </el-form-item>
          <el-form-item label="邮箱" prop="email">
            <el-input v-model="form.email"  clearable  ></el-input>
          </el-form-item>
          <el-form-item label="抽奖时间" prop="time">
            <el-date-picker
              v-model="form.created_at" value-format="X" format="YYYY-MM-DD"
              type="daterange" style="width: 200px;border-radius: 0px;border-left: 0;margin-left: -1px;"
              range-separator="~" prefix-icon=""
              start-placeholder="Start date" end-placeholder="End date"
            >
            </el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" :icon="useRenderIcon('ri:search-line')" :loading="loading" @click="onSearch"> {{ t("buttons.search") }}
            </el-button>
            <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ t("buttons.reset") }}</el-button>
          </el-form-item>
        </el-form>

        <div ref="contentRef" :class="['flex', deviceDetection() ? 'flex-wrap' : '']">
          <PureTableBar
            :class="[isShow && !deviceDetection() ? '!w-[60vw]' : 'w-full']"
            style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
            :title="t(route.meta.title)"
            :columns="columns1"
            @refresh="onSearch"
          >
            <template #title>
              <div></div>
            </template>
            <template v-slot="{ size, dynamicColumns }">
              <pure-table ref="tableRef" align-whole="center" showOverflowTooltip
                          table-layout="auto" :loading="loading" :size="size" adaptive @sort-change="sortChange"
                          :row-style="rowStyle" :adaptiveConfig="{ offsetBottom: 108 }"
                          :data="dataList" :columns="dynamicColumns" :border="true" :pagination="{ ...pagination, size }"  @page-size-change="handleSizeChange"
                          @page-current-change="handleCurrentChange"
                          :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }">
                <template #operation="{ row }">
                  <el-popconfirm :title="t('buttons.deleteConfirm')" @confirm="handleDelete(row)">
                    <template #reference>
                      <el-button v-perms="'order_apply:btn:delete'"  class="reset-margin" link type="primary" :size="size">
                        {{ t("buttons.delete") }}
                      </el-button>
                    </template>
                  </el-popconfirm>
                </template>
              </pure-table>
            </template>
          </PureTableBar>
        </div>
      </el-tab-pane>

    </el-tabs>




  </div>

</template>

<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
:deep(.el-form--inline .el-form-item) {
  margin-right: 10px;
}
.main-content {
  margin: 24px 24px 0 !important;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
:deep(.search_field .el-select__wrapper) {
  border-radius: 0;border-right: 0;
  margin-right: -1px;
}
</style>
